package com.coda.controller;

import com.coda.common.PageResult;
import com.coda.common.Result;
import com.coda.dto.PageDto;
import com.coda.entity.Role;
import com.coda.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/warehouse/role")
@Api(tags = "用户角色相关接口")
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 查询所有用户角色列表
     */
    @GetMapping("/role-list")
    @ApiOperation("查询用户类型列表")
    public Result getUserTypeList(){
        List<Role> roleList = roleService.getRoleList();
        return Result.ok(roleList);
    }

    /**
     * 分页查询角色列表
     */
    @GetMapping("/role-page-list")
    @ApiOperation("分页查询角色列表")
    public Result getRolePage(PageDto pageDto, Role role){
        PageResult pageResult = roleService.getRolePage(pageDto,role);
        return Result.ok(pageResult);
    }

    /**
     * 添加角色
     */
    @PostMapping("/role-add")
    @ApiOperation("添加角色")
    public Result addRole(@RequestBody Role role){
        roleService.addRole(role);
        return Result.ok("添加成功");
    }

    /**
     * 更改角色状态
     */
    @PutMapping("/role-state-update")
    @ApiOperation("更改角色状态")
    public Result updateState(@RequestBody Role role){
        roleService.updateState(role);
        return Result.ok("更改成功");
    }

    /**
     * 根据id删除角色
     */
    @DeleteMapping("/role-delete/{id}")
    @ApiOperation("根据id删除角色")
    public Result deleteRoleById(@PathVariable Long id){
        roleService.deleteRoleById(id);
        return Result.ok("删除成功");
    }

    /**
     * 根据id修改角色
     */
    @PutMapping("/role-update")
    @ApiOperation("根据id修改角色")
    public Result updateRole(@RequestBody Role role){
        roleService.updateRole(role);
        return Result.ok("修改成功");
    }


}
